home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / asmutil / asm_n_z.zip / PAD.ASM < prev    next >
Assembly Source File  |  1987-04-02  |  26KB  |  620 lines

  1. INTERRUPTS      SEGMENT AT 0H   ;This is where the keyboard interrupt
  2.         ORG     9H*4            ;holds the address of its service routine
  3. KEYBOARD_INT    LABEL   WORD  
  4.         ORG     21H*4            ;holds the address of its service routine
  5. DOS_INT        LABEL   WORD  
  6. INTERRUPTS      ENDS
  7.  
  8. SCREEN  SEGMENT AT 0B000H       ;A dummy segment to use as the
  9. SCREEN  ENDS                    ;Extra Segment 
  10.  
  11. ROM_BIOS_DATA   SEGMENT AT 40H  ;BIOS statuses held here, also keyboard buffer
  12.  
  13.         ORG     1AH
  14.         HEAD DW      ?                  ;Unread chars go from Head to Tail
  15.         TAIL DW      ?
  16.         BUFFER       DW      16 DUP (?)         ;The buffer itself
  17.         BUFFER_END   LABEL   WORD
  18.  
  19. ROM_BIOS_DATA   ENDS
  20.  
  21. CODE_SEG        SEGMENT
  22.         ASSUME  CS:CODE_SEG
  23.         ORG     100H            ;ORG = 100H to make this into a .COM file
  24. FIRST:  JMP     LOAD_PAD        ;First time through jump to initialize routine
  25.  
  26.         COPY_RIGHT      DB '(C)1987 S Holzner'
  27.         INT21   LABEL   DWORD   ;Point to next two words for jump.
  28.         OLD_DOS_INT     DW 2 DUP(?)     ;Store original DOS INT21 address here.
  29.         FIRST_FLAG      DB 1            ;First time through? Get COMMAND address
  30.         COMMAND_ADDR    DW ?            ;Store IP of calling routine in COMMAND.
  31.         OLD_DS          DW 1            ;Keep DS:DX of old keyboard buffer.
  32.         OLD_DX          DW 1001H
  33.         KEY1    DB 'SAVE', 0DH 
  34.         KEY2    DB 'save', 0DH 
  35.         KEY3    DB 'Save'
  36.         CR      DB  0DH,0AH,'$'         ;Use this <cr> to send to DOS.
  37.         FILE_DONE       DB      0DH,0AH,'PAD.TXT created.',0DH,0AH,'$'
  38.         CNTRL_N_FLAG    DW      0               ;Cntrl-N on or off
  39.         FILENAME        DB      'PAD.TXT',0
  40.         PAD_CURSOR      DW      0               ;Current position in pad
  41.         CURSOR_STORAGE  DW      0,600,1200,1800,2400  ;Hold cursor each page.
  42.         PAD_OFFSET      DW      0               ;Chooses 1st 250 bytes or 2nd
  43.         PAD_BEGIN       DW      0               ;Beginning of current page.
  44.         PAD_END         DW      599             ;End of current page.
  45.         PAGE_NUMBER     DW      0               ;Page Number 0-4.
  46.         FIRST_POSITION  DW      ?               ;Position of 1st char on screen
  47.         ATTRIBUTE       DB      112 ;Pad Attribute: 1EH better for color screens
  48.         FORE_ATTR       DB      0
  49.         BACK_ATTR       DB      0
  50.         SCREEN_SEG_OFFSET       DW      0       ;0 for mono, 8000H for graphics
  51.         IO_CHAR         DW      ?               ;Holds addr of Put or Get_Char
  52.         STATUS_PORT     DW      ?               ;Video controller status port
  53.         OLD_KEY_INT     LABEL   WORD
  54.         OLD_KEYBOARD_INT        DD      ?       ;Location of old kbd interrupt
  55.  
  56. NEWPAD  PROC    NEAR            ;The keyboard interrupt will now come here.
  57.         ASSUME  CS:CODE_SEG
  58.         PUSH    AX              ;Save the used registers for good form
  59.         PUSH    BX
  60.         PUSH    CX
  61.         PUSH    DX
  62.         PUSH    DI
  63.         PUSH    SI
  64.         PUSH    DS
  65.         PUSH    ES
  66.         PUSHF                   ;First, call old keyboard interrupt
  67.         CALL    OLD_KEYBOARD_INT
  68.  
  69.         ASSUME  DS:ROM_BIOS_DATA        ;Examine the char just put in
  70.         MOV     BX,ROM_BIOS_DATA
  71.         MOV     DS,BX
  72.  
  73.         MOV     BX,TAIL                 ;Point to current tail
  74.         CMP     BX,HEAD                 ;If at head, kbd int has deleted char
  75.         JE      IN                      ;So leave 
  76.         SUB     BX,2                    ;Point to just read in character
  77.         CMP     BX,OFFSET BUFFER        ;Did we undershoot buffer?
  78.         JAE     NO_WRAP                 ;Nope
  79.         MOV     BX,OFFSET BUFFER_END    ;Yes -- move to buffer top
  80.         SUB     BX,2                    ;Point to just read in characterqqq
  81. NO_WRAP:MOV     DX,[BX]                 ;Char in DX now
  82.         CMP     DX,310EH                ;Is the char a Cntrl-N?
  83.         JNE     NOT_CNTRL_N             ;No
  84.         MOV     TAIL,BX                 ;Yes -- delete it from buffer
  85.         NOT     CNTRL_N_FLAG            ;Switch Modes
  86.         CMP     CNTRL_N_FLAG,0          ;Cntrl-N off?
  87.         JNE     CNTRL_N_ON              ;No, only other choice is on
  88. CNTRL_N_OFF:
  89.         LEA     DX,PAD
  90.         MOV     PAD_OFFSET,DX
  91.         ADD     PAD_OFFSET,3000
  92.         LEA     AX,PUT_CHAR             ;Make IO call Put_Char as it scans
  93.         MOV     IO_CHAR,AX              ;over all locations in pad on screen
  94.         CALL    IO                      ;Restore screen
  95. IN:     JMP     OUT                     ;Done
  96. CNTRL_N_ON:
  97.         LEA     DX,PAD
  98.         MOV     PAD_OFFSET,DX
  99.         ADD     PAD_OFFSET,3000
  100.         LEA     AX,GET_CHAR             ;Make IO use Get_char so current screen
  101.         MOV     IO_CHAR,AX              ;is stored
  102.         CALL    IO                      ;Store Screen
  103.         CALL    DISPLAY                 ;And put up the pad
  104.         JMP     OUT                     ;Done here.
  105. NOT_CNTRL_N:
  106.         TEST    CNTRL_N_FLAG,1          ;Is Cntrl-N on?
  107.         JZ      IN                      ;No -- leave
  108.         MOV     TAIL,BX                 ;Yes, delete this char from buffer
  109.         CMP     DX,5300H                ;Decide what to do -- is it a Delete?
  110.         JNE     RUBOUT_TEST             ;No -- try Rubout
  111.         PUSH    DS
  112.         PUSH    CS
  113.         POP     DS
  114.         MOV     BX,PAD_END
  115.         DEC     BX
  116. DEL_LOOP:
  117.         MOV     BYTE PTR [BX],' '       ;Move space to current pad position
  118.         DEC     BX                      ;and go back one
  119.         CMP     BX,PAD_BEGIN
  120.         JNZ     DEL_LOOP                ;until done.
  121.         MOV     BYTE PTR [BX],'_'       ;Put the cursor at the beginning
  122.         MOV     DX,PAD_BEGIN
  123.         MOV     PAD_CURSOR,dx   ;qq         ;And start cursor over
  124.         POP     DS
  125.         CALL    DISPLAY                 ;Put up the new pad on screen
  126.         JMP     OUT                     ;And take our leave
  127. RUBOUT_TEST:
  128.         CMP     DX,0E08H                ;Is it a Rubout?
  129.         JNE     CRLF_TEST               ;No -- try carriage return-line feed
  130.         PUSH    DS
  131.         PUSH    CS
  132.         POP     DS
  133.         MOV     BX,PAD_CURSOR           ;Yes -- get current pad location
  134.         CMP     BX,PAD_BEGIN            ;Are we at beginning?
  135.         JLE     NEVER_MIND              ;Yes -- can't rubout past beginning
  136.         MOV     BYTE PTR [BX-1],'_'           ;And move cursor back one
  137.         DEC     PAD_CURSOR              ;Set the pad location straight
  138.         CMP     BX,PAD_END              ;Save page number.
  139.         JE      NEVER_MIND
  140.         MOV     BYTE PTR [BX],' '       ;No -- move space to current position
  141. NEVER_MIND:
  142.         POP     DS
  143.         CALL    DISPLAY                 ;And put the result on the screen
  144.         JMP     OUT                     ;Done here.
  145. CRLF_TEST:
  146.         CMP     DX,1C0DH                ;Is it a carriage return-line feed?
  147.         JNE     PGUP_TEST               ;No 
  148.         PUSH    DS
  149.         PUSH    CS
  150.         POP     DS
  151.         CALL    CRLF                    ;Yes -- move to next line
  152.         POP     DS
  153.         CALL    DISPLAY                 ;And display result on screen
  154.         JMP     OUT                     ;Done.
  155. PGUP_TEST:
  156.         CMP     DX,4900H
  157.         JNE     PGDN_TEST
  158.         CMP     PAGE_NUMBER,0
  159.         JNE     DEC_PAGE
  160.         JMP     OUT
  161. DEC_PAGE:
  162.         MOV     BX,PAGE_NUMBER          ;STORE PAD CURSOR
  163.         ADD     BX,BX
  164.         MOV     CX,PAD_CURSOR
  165.         MOV     CURSOR_STORAGE[BX],CX
  166.         DEC     PAGE_NUMBER
  167.         SUB     BX,2
  168.         MOV     CX,CURSOR_STORAGE[BX]
  169.         MOV     PAD_CURSOR,CX
  170.  
  171.         MOV     AX,PAGE_NUMBER
  172.         MOV     BX,600
  173.         MUL     BX
  174.         LEA     DX,PAD
  175.         ADD     AX,DX   
  176.         MOV     PAD_BEGIN,AX
  177.         ADD     AX,599
  178.         MOV     PAD_END,AX
  179.         CALL    DISPLAY
  180.         JMP     OUT
  181. PGDN_TEST:
  182.         CMP     DX,5100H
  183.         JNE     F1_TEST
  184.         CMP     PAGE_NUMBER,4
  185.         JNE     INC_PAGE